//
//  MainTabbarController.m
//  LearnDemo
//
//  Created by 龙 on 2018/5/21.
//  Copyright © 2018年 longlong. All rights reserved.
//

#import "MainTabbarController.h"
#import "CoreTableViewController.h"
#import "FunctionTableViewController.h"
#import "ThirdPartyReadTableViewController.h"
#import "MyTableViewController.h"
#import "CoreViewController.h"
#import "CoreCollectionViewController.h"


@interface MainTabbarController ()
@property (nonatomic ,strong) NSArray<__kindof UIViewController *> *tabBarArray;
@end

@implementation MainTabbarController

- (instancetype)init
{
    self = [super init];
    
    if (self)
    {
        self.viewControllers = self.tabBarArray;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    textAttrs[NSForegroundColorAttributeName] = [UIColor blueColor];
    
    // 选中时字体颜色和选中图片颜色一致
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSFontAttributeName] = textAttrs[NSFontAttributeName];
    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
    
    
    // 通过appearance统一设置所有UITabBarItem的文字属性样式
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray<__kindof UIViewController *> *)tabBarArray
{
    if (_tabBarArray == nil)
    {
        CoreTableViewController *coreVC = [[CoreTableViewController alloc] init];
        UINavigationController *coreNav = [[UINavigationController alloc] initWithRootViewController:coreVC];
        coreVC.tabBarItem.title = NSLocalizedString(@"homePage", nil);
        coreVC.navigationItem.title = @"底层实现";
        coreVC.tabBarItem.image  = [[UIImage imageNamed:@"tabbar_Core"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        coreVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_Core_Selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        FunctionTableViewController *functionVC = [[FunctionTableViewController alloc] init];
        UINavigationController *functionNav = [[UINavigationController alloc] initWithRootViewController:functionVC];
        functionVC.tabBarItem.title = @"功能";
        functionVC.navigationItem.title = @"功能";
        functionVC.tabBarItem.image  = [[UIImage imageNamed:@"tabbar_Function"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        functionVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_Function_Selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        
        
        ThirdPartyReadTableViewController *readVC = [[ThirdPartyReadTableViewController alloc] init];
        UINavigationController *readNav = [[UINavigationController alloc] initWithRootViewController:readVC];
        readVC.tabBarItem.title = @"解读";
        readVC.navigationItem.title = @"解读三方库";
        readVC.tabBarItem.image  = [[UIImage imageNamed:@"tabbar_ThirdRead"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        readVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_ThirdRead_Selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        MyTableViewController *myVC = [[MyTableViewController alloc] init];
        UINavigationController *myNav = [[UINavigationController alloc] initWithRootViewController:myVC];
        myVC.tabBarItem.title = @"我的";
        myVC.navigationItem.title = @"个人主页";
        myVC.tabBarItem.image  = [[UIImage imageNamed:@"tabbar_My"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        myVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_My_Selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        
        _tabBarArray = @[coreNav,functionNav,readNav,myNav];
    }
    
    return _tabBarArray;
}


@end
